package com.dmbjz.webdemo.service;


import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Service
@Slf4j
public class StudentService {

    public void getStudentName() {

        //获取当前请求路径（RequestContextFilter 中定义了 RequestContextHolder ，可以实现从任意位置直接获取）
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        //任意位置直接获取，不需要传递参数
        HttpServletRequest request = requestAttributes.getRequest();
        String requestUrl = request.getRequestURI();
        log.info("requestUrl:{}", requestUrl);

    }

}
